package com.yj.suncity.activity.shouye;

import java.util.ArrayList;
import java.util.List;

import com.yj.suncity.R;
import com.yj.suncity.constant.ShareCon;
import com.yj.suncity.constant.URLCon;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class SeeAdvLogoActivity extends Activity implements OnClickListener{

	private Context context;
	private String advId;
	private String adv_userId;
	private int flag;// 1,首页->看广告列表->当前 2，分类信息->看广告列表->当前
	private ImageView mImg_see_adv_logo;
	private String mLogo;
	private String title;
	private ImageLoader imageLoader;
	private DisplayImageOptions options;
	
	private ViewPager pager;
	private LinearLayout lay_view_select;
	private ViewPagerScroll pagerScroll;
	private List<Object> listPaths = new ArrayList<Object>();
	private TextView mTitleText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_see_adv_logo);
		context = this;
		options = new DisplayImageOptions.Builder()
					.showStubImage(R.drawable.android_layout_detail)
					.showImageForEmptyUri(R.drawable.android_layout_detail)
					.showImageOnFail(R.drawable.android_layout_detail)
					.cacheInMemory(true).cacheOnDisc(true)
					//.displayer(new RoundedBitmapDisplayer(10))// 设置成圆角图片
					.bitmapConfig(Bitmap.Config.RGB_565) // 设置图片的解码类型
					.build();
		advId = getIntent().getStringExtra("advid");
		title = getIntent().getStringExtra("title");
		adv_userId = getIntent().getStringExtra("adv_userid");
		flag = getIntent().getIntExtra("flag", -1);
		mLogo=getIntent().getStringExtra("logo");
		mTitleText = (TextView)findViewById(R.id.title);
		mTitleText.setText(title);
		
		lay_view_select = (LinearLayout) findViewById(R.id.lay_view_select);
		RelativeLayout layout = (RelativeLayout) findViewById(R.id.lay_view_page);
		layout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
		pager = (ViewPager) findViewById(R.id.view_pager);
		if (mLogo.contains(",")) {
			String[] string = mLogo.split(",");
			for (String string2 : string) {
				listPaths.add(URLCon.HOST + string2);
			}
		} else {
			listPaths.add(URLCon.HOST+ mLogo);
		}
		
		pagerScroll = new ViewPagerScroll(context, pager,lay_view_select, listPaths);
//		imageLoader=ImageLoader.getInstance();
		mImg_see_adv_logo = (ImageView) findViewById(R.id.img_see_adv_logo);
		mImg_see_adv_logo.setOnClickListener(this);
//		imageLoader.displayImage(URLCon.HOST+mLogo, mImg_see_adv_logo,options);
	}
	@Override
	protected void onResume() {
		if (pagerScroll != null) {
			pagerScroll.startTimer();
		}
		super.onResume();
	}
	@Override
	protected void onPause() {
		if (pagerScroll != null) {
			pagerScroll.stopTimer();
		}
		super.onPause();
	}
	@Override
	public void onClick(View v){
		switch (v.getId()) {
		case R.id.btnHeadBack:
			this.finish();
			break;
		case R.id.img_see_adv_logo:
			Intent intent = new Intent(context, SeeAdvDetailActivity.class);
			intent.putExtra("adv_userid", adv_userId);
			intent.putExtra("advid", advId);
			intent.putExtra("flag", flag);
			startActivity(intent);
			this.finish();
			break;
		default:
			break;
		}
	}

}
